package com.khalil.kkadmin.cms;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.khalil.kkadmin.cms.domain.CmsColumn;
import com.khalil.kkadmin.cms.service.CmsColumnService;
import com.khalil.kkadmin.common.web.ReqBody;
import com.khalil.kkadmin.common.web.RespResult;
import com.khalil.kkadmin.infrastructure.BaseController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cms/column")
public class CmsColumnController extends BaseController<CmsColumnService, CmsColumn, Long> {
    public CmsColumnController(CmsColumnService service) {
        super(service);
    }

    @GetMapping("/listTree")
    public RespResult<List<CmsColumn>> getCmsColumnTree() {
        return RespResult.ok(service.listTree());
    }

    @PostMapping("/dragMove")
    public void dragMove(@RequestBody ReqBody<String> reqBody) {
        String data = reqBody.getData();
        JSONObject jsonObject = JSON.parseObject(data);
        Long id = jsonObject.getLong("id");
        Long refId = jsonObject.getLong("refId");
        String dropType = jsonObject.getString("dropType");
        service.dragMove(id, refId, dropType);
    }
}
